# -*- coding: utf-8 -*-
"""
用户菜单权限API
"""

from typing import List
from fastapi import APIRouter, Depends
from sqlalchemy.ext.asyncio import AsyncSession

from app.core.database import get_db
from app.core.deps import get_current_user, get_tenant_id
from app.models.user import User
from app.services.menu import menu_service
from app.utils.response import ResponseUtil

router = APIRouter()


@router.get("/menus", summary="获取当前用户菜单树")
async def get_user_menus(
    db: AsyncSession = Depends(get_db),
    current_user: User = Depends(get_current_user),
    tenant_id: str = Depends(get_tenant_id)
):
    """获取当前用户的菜单树"""
    menu_tree = await menu_service.get_user_menu_tree(db, current_user.id, tenant_id)
    return ResponseUtil.success(data=menu_tree)


@router.get("/menus/permissions", summary="获取当前用户所有菜单权限")
async def get_user_menu_permissions(
    db: AsyncSession = Depends(get_db),
    current_user: User = Depends(get_current_user),
    tenant_id: str = Depends(get_tenant_id)
):
    """获取当前用户所有菜单权限代码"""
    from app.services.user import user_service
    permissions = await user_service.get_user_permissions(db, current_user.id, tenant_id)
    return ResponseUtil.success(data={"permissions": permissions})